package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.ServiceCategoryPojo;
import com.ruoyi.common.core.domain.entity.ServiceItemPojo;
import com.ruoyi.common.core.domain.entity.ServiceScenePojo;
import com.ruoyi.system.domain.vo.response.ServiceItemVo;
import com.ruoyi.system.mapper.ServiceCategoryMapper;
import com.ruoyi.system.mapper.ServiceItemMapper;
import com.ruoyi.system.mapper.ServiceSceneMapper;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理配置类
 *
 * @author czg
 * @date 2021/9/11 1:51 下午
 */
@Api(tags = "后台管理员配置管理")
@RestController
@RequestMapping("/api/ops")
public class OpsController {


    @Autowired
    private ServiceCategoryMapper categoryMapper;

    @Autowired
    private ServiceSceneMapper serviceSceneMapper;


    @Autowired
    private ServiceItemMapper serviceItemMapper;

    @PostMapping("/category/add")
    @ApiOperation("新增服务类目")
    public AjaxResult addServeCategory(@RequestBody ServiceCategoryPojo categoryPojo) {
        categoryMapper.insert(categoryPojo);
        return AjaxResult.success();
    }

    @PutMapping("/category/update")
    @ApiOperation("修改服务类目")
    public AjaxResult updateServeCategory(@RequestBody ServiceCategoryPojo categoryPojo) {
        categoryMapper.updateById(categoryPojo);
        return AjaxResult.success();
    }

    @DeleteMapping("/category/delete/{id}")
    @ApiOperation("删除服务类目")
    public AjaxResult deleteServeCategory(@PathVariable String id) {
        return AjaxResult.success(categoryMapper.deleteById(id));
    }


    @GetMapping("/category/list")
    @ApiOperation("服务类目列表")
    public AjaxResult<List<ServiceCategoryPojo>> listServeCategory() {
        QueryWrapper<ServiceCategoryPojo> serviceCategoryPojoQueryWrapper = new QueryWrapper<>();
        serviceCategoryPojoQueryWrapper.eq("status", "1");
        return AjaxResult.success(categoryMapper.selectList(serviceCategoryPojoQueryWrapper));
    }

    @PostMapping("/scene/add")
    @ApiOperation("新增服务场景")
    public AjaxResult addServeScene(@RequestBody ServiceScenePojo scenePojo) {
        serviceSceneMapper.insert(scenePojo);
        return AjaxResult.success();
    }

    @PostMapping("/scene/update")
    @ApiOperation("修改服务场景")
    public AjaxResult updateServeScene(@RequestBody ServiceScenePojo scenePojo) {
        serviceSceneMapper.updateById(scenePojo);
        return AjaxResult.success();
    }


    @DeleteMapping("/scene/delete/{id}")
    @ApiOperation("删除服务场景")
    public AjaxResult deleteServeScene(@PathVariable String id) {
        return AjaxResult.success(serviceSceneMapper.deleteById(id));
    }

    @GetMapping("/scene/list")
    @ApiOperation("服务场景列表")
    public AjaxResult<List<ServiceScenePojo>> listServeScene() {
        QueryWrapper<ServiceScenePojo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", "1");
        return AjaxResult.success(serviceSceneMapper.selectList(queryWrapper));
    }


    @PostMapping("/serviceItem/add")
    @ApiOperation("新增服务项")
    public AjaxResult addserviceItem(@RequestBody ServiceItemPojo serviceItemPojo) {
        serviceItemMapper.insert(serviceItemPojo);
        return AjaxResult.success();
    }


    @PostMapping("/serviceItem/list")
    @ApiOperation("服务项列表")
    public AjaxResult<List<ServiceItemVo>> listServiceItem() {
        return AjaxResult.success(serviceItemMapper.findAllServiceItem());
    }
}
